<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="common/common_head :: commonHeader('货源记录录入')"/>
    <link th:href="@{/static/css/plugins/cropper/cropper.min.css}" rel="stylesheet">
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <form class="form-horizontal" method="post" id="SupplyGoodForm">
        <div class="row">
            <div class="form-group">
                <div class="col-sm-8" style="margin-left: 16px">
                    <input class="btn btn-primary" type="button" onclick="save()" value="保存">
                    <button class="btn btn-primary" type="button" onclick="Dialog.closeFrame(window.name)">取 消</button>
                </div>
            </div>
            <!-- 显示 隐藏测试 -->
            <ul id="myTab" class="nav nav-tabs">
                <li class="active">
                    <a href="#basicinformation" linkTab="basicinformation" isActive="true" data-toggle="tab"> 基础信息</a>
                </li>
            </ul>
            <!-- 基本信息 -->
            <div id="basicinformation">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <input id="pkId" name="pkId" th:value="${qualityEntity.pkId}" style="visibility: hidden">
                        <div class="form-group">
                            <label class="col-xs-1 control-label"><span class="required-sign">*</span>物料号：</label>
                            <div class="col-xs-3">
                                <input id="materialCode" name="materialCode" type="text" class="form-control required"
                                       th:value="${qualityEntity.materialCode}" readonly>
                                <input type="hidden" name="createdBy" th:value="${username}">
                            </div>
                            <label class="col-xs-1 control-label"><span class="required-sign">*</span>供应商编码：</label>
                            <div class="col-xs-3">
                                <input id="srmCode" name="srmCode" type="text" class="form-control required"
                                       th:value="${qualityEntity.srmCode}" readonly>
                            </div>
                            <label class="col-sm-1 control-label"><span class="required-sign">*</span>工厂：</label>
                            <div class="col-sm-3">
                                <input class="form-control" id="werks" name="werks" th:value="${qualityEntity.werks}"
                                       readonly>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label"><span class="required-sign">*</span>有效日期开始：</label>
                            <div class="col-sm-3">
                                <input class="form-control required" id="startData" name="startData"
                                       th:value="${#dates.format(qualityEntity.startData,'yyyy-MM-dd')}">
                            </div>
                            <label class="col-sm-1 control-label"><span class="required-sign">*</span>有效结束日期：</label>
                            <div class="col-sm-3">
                                <input class="form-control required" id="priceEndData" name="priceEndData"
                                       value="9999-12-31" disabled/>
                            </div>
                            <label class="col-sm-1 control-label"><span class="required-sign">*</span>原结束日期：</label>
                            <div class="col-sm-3">
                                <input class="form-control required" id="oldEndData" name="oldEndData"
                                       th:value="${#dates.format(qualityEntity.priceEndData,'yyyy-MM-dd')}" readonly/>
                            </div>
                            <div class="col-sm-3" style="display: none">
                                <input class="form-control required" id="supplyNum" name="supplyNum"
                                       th:value="${qualityEntity.supplyNum}" readonly/>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<!-- Chosen -->
<script th:src="@{/static/js/plugins/chosen/chosen.jquery.js}"></script>
<script type="text/javascript">
    // 初始化时间插件
    laydate.render({elem: '#startData'});
    // 初始化时间插件
    laydate.render({elem: '#priceEndData'});
    //初始化所有字典数据
    initDictDataSel();

    //保存
    function save() {
        if ($("#SupplyGoodForm").valid()) {
            //有效期开始和结束不能小于此前的有效期结束日期
            let oldEndData = $("#oldEndData").val();
            let startData = $("#startData").val();
            let priceEndData = $("#priceEndData").val();
            /* if (startData > oldEndData && priceEndData > oldEndData) {*/
            Page.ajaxPOST(ctxPath + "/supplyGood/edit", $('#SupplyGoodForm').serialize(), function (res) {
                if (res.code == 0) {
                    Dialog.msg("保存成功!");
                    parent.refresh();
                    Dialog.closeFrame(window.name);
                } else {
                    Dialog.errorMsg(res.result);
                }
            }, {"loadingMsg": "正在往服务器提交数据……"});
            /*else {
               Dialog.errorMsg("有效期开始和结束不能小于原有效结束日期!");
               return false;
           }*/
        }
    }
</script>

</body>
</html>
